feat: Embed Thank You Element in Joint SDK#89
feat: Embed Thank You Element in Joint SDK#89zach-will wants to merge 6 commits intomparticle-integrations:mainfrom
Conversation
rmi22186
left a comment
There was a problem hiding this comment.
Looking good! Can you add a few tests also?
| return [protocol, resolvedDomain].join(''); | ||
| } | ||
|
|
||
| function loadRoktScript(scriptId: string, source: string, appendToTarget: boolean = true) { |
There was a problem hiding this comment.
I think this should be a void, there isn't a need to return anything, unless I'm mistaken
There was a problem hiding this comment.
We return the script tag because we handle appending the script to the document differently for TYE and WSDK. For TYE we append the script to document as soon as the script is created, for WSDK we append script to document once the script has finished loading.
I wasn't sure if there was a reason why WSDK script is appended to the DOM much later, but I didn't want to break any behavior that could be related.
There was a problem hiding this comment.
I see now. There's different behavior happening when creating scripts for TYE vs Rokt SDK because of onLoad/onError. The
how about something like:
function loadRoktScript(
scriptId: string,
source: string,
handlers?: { onload?: () => void; onerror?: (e: Event | string) => void },
): void {
if (document.getElementById(scriptId)) return; // resolves the preexisting script issue
const target = document.head || document.body;
const script = document.createElement('script');
script.id = scriptId;
script.type = 'text/javascript';
script.src = source;
script.async = true;
script.crossOrigin = 'anonymous';
(script as HTMLScriptElement & { fetchPriority: string }).fetchPriority = 'high';
if (handlers?.onload) script.onload = handlers.onload;
if (handlers?.onerror) script.onerror = handlers.onerror;
target.appendChild(script);
}
There was a problem hiding this comment.
It has to delay appending due to having the onload/onerror
rmi22186
left a comment
There was a problem hiding this comment.
LGTM. Will do some testing first to make sure existing script loading is unaffected. Then will merge and release tomorrow
Background
Today, partners need to load Rokt resources independently in order to use shoppable ads. This has introduced confusion and added integration complexity. To simplify this, the Joint SDK will now be responsible for fetching the Thank You Element (TYE).
What Changed
thank-you-journeyextension as a special case. When this extension is present, it is no longer appended to the Rokt launcher URL. Instead, Rokt kit will fetch the TYE resource and register the extension with WSDK.mParticle.rokt.usehas been deprecated, as this functionality is now handled internally.Testing and Verification
Media
TODO
Expected config: